<?php  // SCRIPT RELATES TO RESELLER.PHP.
include_once('ClsSebent/config.php');
$on_site_id= $_SESSION['SITE_ID'];
$qry="Select * from site_home where id=101";
$res=mysql_query($qry);
$row=mysql_fetch_array($res);
//collect attributes
//1. CHANGE THE GENERAL SETTINGS.
$logo=mysql_escape_string($row["logo"]);
$logo_alt=mysql_escape_string($row["logo_alt"]);
$company_name=mysql_escape_string($row["company_name"]);
$company_name_img=mysql_escape_string($row["company_name_img"]);
$company_name_img_alt=mysql_escape_string($row["company_name_img_alt"]);
$slogan=mysql_escape_string($row["slogan"]);
$contact_info=mysql_escape_string($row["contact_info"]);
$copyright=mysql_escape_string($row["copyright"]);
$page_bg_image=mysql_escape_string($row["page_bg_image"]);
$page_bg_image_alt=mysql_escape_string($row["page_bg_image_alt"]);
$page_bg_color=mysql_escape_string($row["page_bg_color"]);
$page_text_color=mysql_escape_string($row["page_text_color"]);
$page_link_text_color=mysql_escape_string($row["page_link_text_color"]);
$page_link_visited_color=mysql_escape_string($row["page_link_visited_color"]);
$page_link_rollover_color=mysql_escape_string($row["page_link_rollover_color"]);
$menu_link_text_color=mysql_escape_string($row["menu_link_text_color"]);
$menu_link_visited_color=mysql_escape_string($row["menu_link_visited_color"]);
$menu_link_rollover_color=mysql_escape_string($row["page_link_rollover_color"]);
$meta_keywords=mysql_escape_string($row["meta_keywords"]);
$meta_description=mysql_escape_string($row["meta_description"]);
$meta_title=mysql_escape_string($row["meta_title"]);
$paypal_id=mysql_escape_string($row["paypal_id"]);
$payment_ins=mysql_escape_string($row["payment_ins"]);
$product_profit_pct=mysql_escape_string($row["product_profit_pct"]);
$product_tax_pct=mysql_escape_string($row["product_tax_pct"]);
$product_shipping_amt=mysql_escape_string($row["product_shipping_amt"]);
$sync_logo=mysql_escape_string($row["sync_logo"]);
$sync_navbar=mysql_escape_string($row["sync_navbar"]);
$sync_contact_info=mysql_escape_string($row["sync_contact_info"]);
$sync_skin=mysql_escape_string($row["sync_skin"]);
$sync_paypal=mysql_escape_string($row["sync_paypal"]);
$sync_pricing=mysql_escape_string($row["sync_pricing"]);
$sync_meta=mysql_escape_string($row["sync_meta"]);
$sync_all=mysql_escape_string($row["sync_all"]);
$page_title_color=mysql_escape_string($row["page_title_color"]);
$tax_pct=mysql_escape_string($row["tax_pct"]);
$pro_pct=mysql_escape_string($row["pro_pct"]);

$uqry="UPDATE site_home SET logo='$logo', logo_alt='$logo_alt', company_name='$company_name', company_name_img='$company_name_img', company_name_img_alt='$company_name_img_alt', slogan='$slogan', contact_info='$contact_info', copyright='$copyright', page_bg_image='$page_bg_image', page_bg_image_alt='$page_bg_image_alt', page_bg_color='$page_bg_color', page_text_color='$page_text_color', page_link_text_color='$page_link_text_color', page_link_visited_color='$page_link_visited_color', page_link_rollover_color='$page_link_rollover_color', menu_link_text_color='$menu_link_text_color', menu_link_visited_color='$menu_link_visited_color', menu_link_rollover_color='$menu_link_rollover_color', meta_keywords='$meta_keywords', meta_description='$meta_description', meta_title='$meta_title', paypal_id='$paypal_id', payment_ins='$payment_ins', product_profit_pct='$product_profit_pct', product_tax_pct='$product_tax_pct', product_shipping_amt='$product_shipping_amt', sync_logo='$sync_logo', sync_navbar='$sync_navbar', sync_contact_info='$sync_contact_info', sync_skin='$sync_skin', sync_paypal='$sync_paypal',  sync_pricing='$sync_pricing', sync_meta='$sync_meta', sync_all='$sync_all', page_title_color='$page_title_color', tax_pct='$tax_pct', pro_pct='$pro_pct' WHERE id=".$on_site_id;
$uqry=$uqry;
//echo $uqry;
mysql_query($uqry);
// CHANGED GENERAL SETTINGS.....................................

//2. CHANGE THE PAGES WITH ADMIN PAGES.
//remove existing pages.
$dpq="DELETE from site_page where site_id=".$on_site_id;
mysql_query($dpq);

//insert pages from admin.
$rsql="Select * from site_page where site_id=101";
$rres=mysql_query($rsql);
		while($rrow=mysql_fetch_array($rres))
		{
			$Iqry="INSERT INTO site_page (site_id, page_title, page_content, page_content_img, page_content_img_alt, page_content_ic, banner, banner_link, meta_keywords, meta_description, meta_title) VALUES ('$on_site_id','" . mysql_escape_string($rrow["page_title"]) . "','" . mysql_escape_string($rrow["page_content"]) ."', '" . $rrow["page_content_img"] . "', '" . $rrow["page_content_img_alt"] . "', 'C', '" . $rrow["banner"] . "', '" . $rrow["banner_link"] . "', '" . $rrow["meta_keywords"] ."', '" . $rrow["meta_description"] . "', '" . $rrow["meta_title"] . "')";
			//echo $Iqry;
			mysql_query($Iqry);
		}
//PAGES CHANGED.................................................

//3. CHANGE THE NAVIGATION BAR WITH ADMIN LINKS.
$dlq="DELETE from site_navbar where site_id=".$on_site_id;
mysql_query($dlq);
$new_nav_res = mysql_query("SELECT MAX(id) FROM site_navbar");
$new_nav_row = mysql_fetch_row($new_nav_res);
$new_navbar_base=$new_nav_row[0] + 1;
		
$nsql="select * from site_navbar where site_id=101 ORDER BY link_position, link_text ";
$nres=mysql_query($nsql);
while($nrow=mysql_fetch_array($nres))
	{
		$page_title=mysql_escape_string($nrow["link_page_title"]);
		$link_text=mysql_escape_string($nrow["link_text"]);
		$link_page_title=mysql_escape_string($nrow["link_page_title"]);
		$link_parent=$nrow["link_parent"];
		$link_position=$nrow["link_position"];
		$new_navbar_id=$new_navbar_base;		
		$new_link_parent=0;
		//GET Link Parent Id.	
			
		if($link_parent!=0)
		{
		$pqry="select * from site_navbar where id=$link_parent";
		$pres=mysql_query($pqry);
		
		if($prow=mysql_fetch_array($pres))
		$parent_title=mysql_escape_string($prow["link_page_title"]);
		
		if($parent_title!="")
		{
		$piqry="select * from site_navbar where site_id='$on_site_id' and link_page_title='$parent_title'";
		//echo $piqry;
		$pires=mysql_query($piqry);
		if($pirow=mysql_fetch_array($pires))		
		$new_link_parent=mysql_escape_string($pirow["id"]);		
		}
		}
		//GET Link Page Id.
		$nqry="select * from site_page where site_id='$on_site_id' and page_title='$page_title'";		
//		echo $nqry;
		$nvres=mysql_query($nqry);
		if($nvrow=mysql_fetch_array($nvres))
		$new_link_page=$nvrow["id"];
		//echo "<BR>".$new_link_page;
		$Inqry="INSERT INTO site_navbar VALUES($new_navbar_id, $on_site_id, '$link_text', $new_link_page, '$page_title', $new_link_parent, '$link_position','Y')";
		//echo $Inqry;
		mysql_query($Inqry);
		$new_navbar_base++;
	}//Links Inserted	
//NAVIGATION BAR CHANGED........................................

header('Location: settings.php?site_id='.$on_site_id);
?>